//
//  ChangChuVC.m
//  Hand-held_kitchen
//
//  Created by 张张烨 on 16/1/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ChangChuVC.h"
#import "ZongTouwenjian.pch"
#import "ZhangChuCell.h"
#import "ZuiXinWebView.h"
#import "Zhuangchumoble.h"
@interface ChangChuVC ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)NSMutableArray *zuixinArr;// 最新数据数组
@property(nonatomic,retain)UICollectionView *collection;

@end

@implementation ChangChuVC

-(void)dealloc
{
    [_zuixinArr release];
    [_collection release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self collectionData];
    [self KELAISHENVIEW];
    
}
/**<  coll嘚数据 */
-(void)collectionData
{
    NSString *str =[NSString stringWithFormat:@"http://api.izhangchu.com/?topic_id=%@&methodName=ShequList&size=20&is_marrow=0&page=1&version=4.3&",self.str];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:str parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSArray *arr = responseObject[@"data"][@"data"];
        self.zuixinArr = [Zhuangchumoble modelHanderWithArray:arr];
        
        
        [_collection reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
/**<  coll */
-(void)KELAISHENVIEW
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    // cell大小
    layout.itemSize = CGSizeMake((372/2) * KUAN, 249 * GAO);
    // 行列间距
    layout.minimumLineSpacing = 10 * KUAN;
    layout.minimumInteritemSpacing = 1 *GAO;
    // 边界
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // 滚动方向
    // 创建过程类似tableView
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Width, Height) collectionViewLayout:layout];
    _collection.backgroundColor = [UIColor whiteColor];
    _collection.delegate = self;
    _collection.dataSource = self;
    [self.view addSubview:_collection];
    [_collection registerClass:[ZhangChuCell class] forCellWithReuseIdentifier:@"cell1"];
    
    
}
/**<  coll的tiem*/
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _zuixinArr.count;
}
/**<  Cell*/
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZhangChuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
    Zhuangchumoble *m = _zuixinArr[indexPath.item];
    
    [cell.tupian sd_setImageWithURL:[NSURL URLWithString:m.image]];
    [cell.touxiang sd_setImageWithURL:[NSURL URLWithString:m.head_img]];
    cell.nicheng.text = m.nick;
    cell.shijian.text = m.create_time;
    
    
    return cell;
}
// collection 点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZuiXinWebView *dierye = [[ZuiXinWebView alloc]init];
    Zhuangchumoble *m = _zuixinArr[indexPath.row];
    /**<  传过去的网址 */
    dierye.str =m.share_url;
   
    [self.navigationController pushViewController:dierye animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
